<%@ page language="java" import="java.util.*" contentType="text/html; charset=gb2312" pageEncoding="utf-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";


%>
<%
String username = (String)session.getAttribute("name");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>WDB Home</title>
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<!--
	<link rel="stylesheet" type="text/css" href="styles.css">
	-->
<link href="./css/demo-9d2e853776642d42fb65e9d7209f4978.css" media="screen" rel="stylesheet">

<style type="text/css"> 
*{ margin:0px; padding:0;}
body {
	background: #2E3444;
	font-size: 100%;
	line-height: 1.25;
	font-family: 'Lato', sans-serif;
	font-weight: 300;
}
/*---------------------------------------demo css--------------------------------------------*/
#container{ text-align:center ;}
#container .cell{ padding:5px 5px 0; border:1px solid #E3E3E3; background:#F5F5F5; margin-top:10px}
#container p{ line-height:20px; margin-top:5px}
/*-----------------------------------------------------------------------------------*/
</style> 
<script type="text/javascript" src="http://www.js-css.cn/jscode/jquery.min.js"></script>
<!----------------------------------------------------demo js---------------------------------------------------->
<script type="text/javascript">
/**
 ************************************************************
 ***@project jquery瀑布流插件
 ***@ver version 1.0
 ************************************************************
 */
;(function($){
   var 
   //参数
   setting={
      column_width:204,//列宽
	  column_className:'waterfall_column',//列的类名
	  column_space:10,//列间距
	  cell_selector:'.cell',//要排列的砖块的选择器，context为整个外部容器
	  img_selector:'img',//要加载的图片的选择器
	  auto_imgHeight:true,//是否需要自动计算图片的高度
	  fadein:true,//是否渐显载入
	  fadein_speed:600,//渐显速率，单位毫秒
	  insert_type:1, //单元格插入方式，1为插入最短那列，2为按序轮流插入
	  getResource:function(index){ }  //获取动态资源函数,必须返回一个砖块元素集合,传入参数为加载的次数
   },
   //
   waterfall=$.waterfall={},//对外信息对象
   $container=null;//容器
   waterfall.load_index=0, //加载次数
   $.fn.extend({
       waterfall:function(opt){
		  opt=opt||{};  
	      setting=$.extend(setting,opt);
		  $container=waterfall.$container=$(this);
		  waterfall.$columns=creatColumn();
		  render($(this).find(setting.cell_selector).detach(),false); //重排已存在元素时强制不渐显
		  waterfall._scrollTimer2=null;
		  $(window).bind('scroll',function(){
		     clearTimeout(waterfall._scrollTimer2);
			 waterfall._scrollTimer2=setTimeout(onScroll,300);
		  });
		  waterfall._scrollTimer3=null;
		  $(window).bind('resize',function(){
		     clearTimeout(waterfall._scrollTimer3);
			 waterfall._scrollTimer3=setTimeout(onResize,300);
		  });
	   }
   });
   function creatColumn(){//创建列
      waterfall.column_num=calculateColumns();//列数
	  //循环创建列
	  var html='';
	  for(var i=0;i<waterfall.column_num;i++){
	     html+='<div class="'+setting.column_className+'" style="width:'+setting.column_width+'px; display:inline-block; *display:inline;zoom:1; margin-left:'+setting.column_space/2+'px;margin-right:'+setting.column_space/2+'px; vertical-align:top; overflow:hidden"></div>';
	  }
	  $container.prepend(html);//插入列
	  return $('.'+setting.column_className,$container);//列集合
   }
   function calculateColumns(){//计算需要的列数
      var num=Math.floor(($container.innerWidth())/(setting.column_width+setting.column_space));
	  if(num<1){ num=1; } //保证至少有一列
	  return num;
   }
   function render(elements,fadein){//渲染元素
      if(!$(elements).length) return;//没有元素
      var $columns = waterfall.$columns;
      $(elements).each(function(i){										
		  if(!setting.auto_imgHeight||setting.insert_type==2){//如果给出了图片高度，或者是按顺序插入，则不必等图片加载完就能计算列的高度了
		     if(setting.insert_type==1){ 
			    insert($(elements).eq(i),setting.fadein&&fadein);//插入元素
			 }else if(setting.insert_type==2){
			    insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素	 
		     }
			 return true;//continue
		  }						
		  if($(this)[0].nodeName.toLowerCase()=='img'||$(this).find(setting.img_selector).length>0){//本身是图片或含有图片
		      var image=new Image;
			  var src=$(this)[0].nodeName.toLowerCase()=='img'?$(this).attr('src'):$(this).find(setting.img_selector).attr('src');
			  image.onload=function(){//图片加载后才能自动计算出尺寸
			      image.onreadystatechange=null;
				  if(setting.insert_type==1){ 
				     insert($(elements).eq(i),setting.fadein&&fadein);//插入元素
				  }else if(setting.insert_type==2){
					 insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素	 
				  }
				  image=null;
			  }
			  image.onreadystatechange=function(){//处理IE等浏览器的缓存问题：图片缓存后不会再触发onload事件
			      if(image.readyState == "complete"){
					 image.onload=null;
					 if(setting.insert_type==1){ 
					    insert($(elements).eq(i),setting.fadein&&fadein);//插入元素
					 }else if(setting.insert_type==2){
					    insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素	 
					 }
					 image=null;
				  }
			  }
			  image.src=src;
		  }else{//不用考虑图片加载
		      if(setting.insert_type==1){ 
				 insert($(elements).eq(i),setting.fadein&&fadein);//插入元素
			  }else if(setting.insert_type==2){
				 insert2($(elements).eq(i),i,setting.fadein&&fadein);//插入元素	 
			  }
		  }						
	  });
   }
   function public_render(elems){//ajax得到元素的渲染接口
   	  render(elems,true);	
   }
   function insert($element,fadein){//把元素插入最短列
      if(fadein){//渐显
	     $element.css('opacity',0).appendTo(waterfall.$columns.eq(calculateLowest())).fadeTo(setting.fadein_speed,1);
	  }else{//不渐显
         $element.appendTo(waterfall.$columns.eq(calculateLowest()));
	  }
   }
   function insert2($element,i,fadein){//按序轮流插入元素
      if(fadein){//渐显
	     $element.css('opacity',0).appendTo(waterfall.$columns.eq(i%waterfall.column_num)).fadeTo(setting.fadein_speed,1);
	  }else{//不渐显
         $element.appendTo(waterfall.$columns.eq(i%waterfall.column_num));
	  }
   }
   function calculateLowest(){//计算最短的那列的索引
      var min=waterfall.$columns.eq(0).outerHeight(),min_key=0;
	  waterfall.$columns.each(function(i){						   
		 if($(this).outerHeight()<min){
		    min=$(this).outerHeight();
			min_key=i;
		 }							   
	  });
	  return min_key;
   }
   function getElements(){//获取资源
      $.waterfall.load_index++;
      return setting.getResource($.waterfall.load_index,public_render);
   }
   waterfall._scrollTimer=null;//延迟滚动加载计时器
   function onScroll(){//滚动加载
      clearTimeout(waterfall._scrollTimer);
	  waterfall._scrollTimer=setTimeout(function(){
	      var $lowest_column=waterfall.$columns.eq(calculateLowest());//最短列
		  var bottom=$lowest_column.offset().top+$lowest_column.outerHeight();//最短列底部距离浏览器窗口顶部的距离
		  var scrollTop=document.documentElement.scrollTop||document.body.scrollTop||0;//滚动条距离
		  var windowHeight=document.documentElement.clientHeight||document.body.clientHeight||0;//窗口高度
		  if(scrollTop>=bottom-windowHeight){
			 render(getElements(),true);
		  }
	  },100);
   }
   function onResize(){//窗口缩放时重新排列
      if(calculateColumns()==waterfall.column_num) return; //列数未改变，不需要重排
      var $cells=waterfall.$container.find(setting.cell_selector);
	  waterfall.$columns.remove();
	  waterfall.$columns=creatColumn();
      render($cells,false); //重排已有元素时强制不渐显
   }
})(jQuery);
</script>
<script type="text/javascript">
 $(document).ready(function () { 
 		var n = "<%=username%>";
         if(n==null||n=="")
           alert("you are not signed in!");
        function fixHeight() {
      
            var headerHeight = $("#switcher").height();
      
            $("#iframe").attr("height", $(window).height() - 54 + "px");
      
        }
      
        $(window).resize(function () {
      
            fixHeight();
      
        }).resize();
      
      
        $('.icon-monitor').addClass('active');
      
        
        $(".icon-mobile-1").click(function () {
            window.location.href="./mycollects.jsp";
            return false;
        });
      
        $(".icon-tablet").click(function () {
            $("#by").css("overflow-y", "auto");
            $('#iframe-wrap').removeClass().addClass('tablet-width');
            $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
            $(this).addClass('active');
            return false;
        });
      
        $(".icon-monitor").click(function () {
            $("#by").css("overflow-y", "hidden");
            $('#iframe-wrap').removeClass().addClass('full-width');
            $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
            $(this).addClass('active');
            return false;
        });

        $(".remove_frame").click(function () {
            if(n!=null||n!="")
              window.location.href="./home.jsp";
            else
              window.location.href="./login.jsp";
            return false;
        });
        
        $(".logout").click(function () {
            if(n!=null||n!="")
             {
              window.location.href="./login.jsp?do=out";
            }else
              window.location.href="./login.jsp";
            return false;
        });
      });  
      
      function Responsive($a) {
          if ($a == true) $("#Device").css("opacity", "100");
          if ($a == false) $("#Device").css("opacity", "0");
          $('#iframe-wrap').removeClass().addClass('full-width');
          $('.icon-tablet,.icon-mobile-1,.icon-monitor,.icon-mobile-2,.icon-mobile-3').removeClass('active');
          $(this).addClass('active');
          return false;
      }; 
    </script>
<!-------------------------------------------------------------------------------------------------------->
</head>
<body>
<!----------------------------------------------------demo html---------------------------------------------------->

<div class="frame_wrap">
<div class="pace-activity"></div></div>
    <div id="switcher">
      <div class="center">
        <ul>
          <div id="Device">
            <li class="device-mobile">
              <a href="javascript:">
              <div class="icon-mobile-1">收藏</div>
              </a>
            </li>
            <li class="logoTop">
              <a href="./home.jsp">首页</a>
            </li>
            
            <li class="remove_frame">
              <a href="javascript:" >在线用户：<%=username%></a>
            </li>
            <li class="logout">
              <a href="javascript:">退出</a>
            </li>
          </div>
        </ul>
      </div>
    </div>
<div id="container" style="margin-top: 60px">
    <div class="cell"><img src="./img/00.jpg" alt="jQuery瀑布流插件图片加载"/><p>00</p></div>
    <div class="cell"><img src="./img/01.jpg" alt="jQuery瀑布流插件图片加载"/><p>01</p></div>
    <div class="cell"><img src="./img/02.jpg" alt="jQuery瀑布流插件图片加载"/><p>02</p></div>
    <div class="cell"><img src="./img/03.jpg" alt="jQuery瀑布流插件图片加载"/><p>03</p></div>
    <div class="cell"><img src="./img/04.jpg" alt="jQuery瀑布流插件图片加载"/><p>04</p></div>
    <div class="cell"><img src="./img/05.jpg" alt="jQuery瀑布流插件图片加载"/><p>05</p></div>
    <div class="cell"><img src="./img/06.jpg" alt="jQuery瀑布流插件图片加载"/><p>06</p></div>
    <div class="cell"><img src="./img/07.jpg" alt="jQuery瀑布流插件图片加载"/><p>07</p></div>
    <div class="cell"><img src="./img/08.jpg" alt="jQuery瀑布流插件图片加载"/><p>08</p></div>
    <div class="cell"><img src="./img/09.jpg" alt="jQuery瀑布流插件图片加载"/><p>09</p></div>
    <div class="cell"><img src="./img/10.jpg" alt="jQuery瀑布流插件图片加载"/><p>10</p></div>
    <div class="cell"><img src="./img/11.jpg" alt="jQuery瀑布流插件图片加载"/><p>11</p></div>
    <div class="cell"><img src="./img/12.jpg" alt="jQuery瀑布流插件图片加载"/><p>12</p></div>
    <div class="cell"><img src="./img/13.jpg" alt="jQuery瀑布流插件图片加载"/><p>13</p></div>
    <div class="cell"><img src="./img/14.jpg" alt="jQuery瀑布流插件图片加载"/><p>14</p></div>
    <div class="cell"><img src="./img/15.jpg" alt="jQuery瀑布流插件图片加载"/><p>15</p></div>
    <div class="cell"><img src="./img/16.jpg" alt="jQuery瀑布流插件图片加载"/><p>16</p></div>
    <div class="cell"><img src="./img/17.jpg" alt="jQuery瀑布流插件图片加载"/><p>17</p></div>
    <div class="cell"><img src="./img/18.jpg" alt="jQuery瀑布流插件图片加载"/><p>18</p></div>
    <div class="cell"><img src="./img/19.jpg" alt="jQuery瀑布流插件图片加载"/><p>19</p></div>
</div>
</div>
<script>
var opt={
  getResource:function(index,render){//index为已加载次数,render为渲染接口函数,接受一个dom集合或jquery对象作为参数。通过ajax等异步方法得到的数据可以传入该接口进行渲染，如 render(elem)
	  if(index>=6) 
	  	index=index%6+1;
	  var html='';
	  for(var i=20*(index-1);i<20*(index-1)+20;i++){
		 var k='';
		 for(var ii=0;ii<3-i.toString().length;ii++){
	        k+='0';
		 }
		 k+=i;
	     var src="http://cued.xunlei.com/demos/publ/img/P_"+k+".jpg";
		 html+='<div class="cell"><img src="'+src+'" /><p>'+k+'</p></div>';
	  }
	  return $(html);
  },
  auto_imgHeight:true,
  insert_type:1
}
$('#container').waterfall(opt);
</script>
<!-------------------------------------------------------------------------------------------------------->
  </body>
</html>
